/* GTK - The GIMP Toolkit
* gtkcupsutils.h: Statemachine implementation of POST and GET
* cup calls which can be used to create a non-blocking cups API
- * Copyright (C) 2003, Red Hat, Inc.
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
if (server)
request->server = g_strdup (server);
else
- request->server = g_strdup (cupsServer());
+ request->server = g_strdup (cupsServer ());
if (resource)
else
{
request->http = NULL;
- request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+ request->http = httpConnectEncrypt (request->server,
+ ippPort (),
+ cupsEncryption ());
if (request->http)
httpBlocking (request->http, 0);
request->attempts = 0;
request->data_io = data_io;
- request->ipp_request = ippNew();
+ request->ipp_request = ippNew ();
request->ipp_request->request.op.operation_id = operation_id;
request->ipp_request->request.op.request_id = 1;
gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name",
- NULL, cupsUser());
+ NULL, cupsUser ());
cupsLangFree (language);
gtk_cups_request_free (GtkCupsRequest *request)
{
if (request->own_http)
- if (request->http)
- httpClose (request->http);
+ {
+ if (request->http)
+ httpClose (request->http);
+ }
if (request->ipp_request)
ippDelete (request->ipp_request);
gtk_cups_request_read_write (GtkCupsRequest *request)
{
if (request->type == GTK_CUPS_POST)
- post_states[request->state](request);
+ post_states[request->state] (request);
else if (request->type == GTK_CUPS_GET)
- get_states[request->state](request);
+ get_states[request->state] (request);
if (request->attempts > _GTK_CUPS_MAX_ATTEMPTS &&
request->state != GTK_CUPS_REQUEST_DONE)
return TRUE;
}
else
- {
- return FALSE;
- }
+ return FALSE;
}
GtkCupsPollState
result = IPP_TAG_ZERO;
lower_bound = 0;
- upper_bound = num_options = (int)(sizeof(ipp_options) / sizeof(ipp_options[0])) - 1;
+ upper_bound = num_options = (int) G_N_ELEMENTS (ipp_options) - 1;
while (1)
{
int match;
current_option = (int) (((upper_bound - lower_bound) / 2) + lower_bound);
- match = strcasecmp(option, ipp_options[current_option].name);
+ match = strcasecmp (option, ipp_options[current_option].name);
if (match == 0)
{
result = ipp_options[current_option].value_tag;
{
ipp_tag_t option_tag;
- g_assert (option != NULL);
- g_assert (value != NULL);
+ g_return_if_fail (option != NULL);
+ g_return_if_fail (value != NULL);
option_tag = _find_option_tag (option);
case IPP_TAG_BOOLEAN:
{
char b;
- b = 0;
- if (!strcasecmp(value, "true") ||
- !strcasecmp(value, "on") ||
- !strcasecmp(value, "yes"))
+
+ if (strcasecmp (value, "true") == 0 ||
+ strcasecmp (value, "on") == 0 ||
+ strcasecmp (value, "yes") == 0)
b = 1;
-
- ippAddBoolean(request->ipp_request,
- IPP_TAG_JOB,
- option,
- b);
+ else
+ b = 0;
+
+ ippAddBoolean (request->ipp_request,
+ IPP_TAG_JOB,
+ option,
+ b);
break;
}
s = (char *)value;
}
else
- lower = strtol(value, &s, 0);
+ lower = strtol (value, &s, 0);
if (*s == '-')
{
if (s[1])
- upper = strtol(s + 1, NULL, 0);
+ upper = strtol (s + 1, NULL, 0);
else
upper = 2147483647;
}
int yres;
ipp_res_t units;
- xres = strtol(value, &s, 0);
+ xres = strtol (value, &s, 0);
if (*s == 'x')
- yres = strtol(s + 1, &s, 0);
+ yres = strtol (s + 1, &s, 0);
else
yres = xres;
- if (strcasecmp(s, "dpc") == 0)
+ if (strcasecmp (s, "dpc") == 0)
units = IPP_RES_PER_CM;
else
units = IPP_RES_PER_INCH;
if (request->http == NULL)
{
- request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+ request->http = httpConnectEncrypt (request->server,
+ ippPort (),
+ cupsEncryption ());
if (request->http == NULL)
request->attempts++;
if (request->data_io != NULL)
{
fstat (g_io_channel_unix_get_fd (request->data_io), &data_info);
- sprintf (length, "%lu", (unsigned long)ippLength(request->ipp_request) + data_info.st_size);
+ sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request) + data_info.st_size);
}
else
- {
- sprintf (length, "%lu", (unsigned long)ippLength(request->ipp_request));
- }
+ sprintf (length, "%lu", (unsigned long) ippLength (request->ipp_request));
- httpClearFields(request->http);
- httpSetField(request->http, HTTP_FIELD_CONTENT_LENGTH, length);
- httpSetField(request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
+ httpClearFields (request->http);
+ httpSetField (request->http, HTTP_FIELD_CONTENT_LENGTH, length);
+ httpSetField (request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
#ifdef HAVE_HTTP_AUTHSTRING
- httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
+ httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
#endif
- if (httpPost(request->http, request->resource))
+ if (httpPost (request->http, request->resource))
{
- if (httpReconnect(request->http))
+ if (httpReconnect (request->http))
{
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
request->poll_state = GTK_CUPS_HTTP_WRITE;
- ipp_status = ippWrite(request->http, request->ipp_request);
+ ipp_status = ippWrite (request->http, request->ipp_request);
if (ipp_status == IPP_ERROR)
{
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "%s",ippErrorString (cupsLastError ()));
+ gtk_cups_result_set_error (request->result,
+ "%s",
+ ippErrorString (cupsLastError ()));
return;
}
request->poll_state = GTK_CUPS_HTTP_WRITE;
if (httpCheck (request->http))
- http_status = httpUpdate(request->http);
+ http_status = httpUpdate (request->http);
else
http_status = request->last_status;
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "Error reading from cache file: %s", error->message);
+ gtk_cups_result_set_error (request->result,
+ "Error reading from cache file: %s",
+ error->message);
g_error_free (error);
return;
#if HAVE_CUPS_API_1_2
- if (httpWrite2(request->http, buffer, bytes) < bytes)
+ if (httpWrite2 (request->http, buffer, bytes) < bytes)
#else
- if (httpWrite(request->http, buffer, (int) bytes) < bytes)
+ if (httpWrite (request->http, buffer, (int) bytes) < bytes)
#endif /* HAVE_CUPS_API_1_2 */
{
+ int http_errno;
+
+ http_errno = httpError (request->http);
+
request->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
- gtk_cups_result_set_error (request->result, "Error writting to socket in Post %s", strerror (httpError (request->http)));
+ gtk_cups_result_set_error (request->result,
+ "Error writing to socket in Post %s",
+ g_strerror (http_errno));
return;
}
}
httpReconnect (request->http);
/* Upgrade with encryption... */
- httpEncryption(request->http, HTTP_ENCRYPT_REQUIRED);
+ httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
request->attempts++;
goto again;
else
{
request->state = GTK_CUPS_POST_DONE;
- gtk_cups_result_set_error (request->result, "HTTP Error in POST %s", strerror (http_errno));
+ gtk_cups_result_set_error (request->result,
+ "HTTP Error in POST %s",
+ g_strerror (http_errno));
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
return;
}
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
request->last_status = HTTP_CONTINUE;
httpClose (request->http);
if (ipp_status == IPP_ERROR)
{
- gtk_cups_result_set_error (request->result, "%s", ippErrorString (cupsLastError()));
+ gtk_cups_result_set_error (request->result, "%s",
+ ippErrorString (cupsLastError ()));
ippDelete (request->result->ipp_response);
request->result->ipp_response = NULL;
if (request->data_io == NULL)
{
- gtk_cups_result_set_error (request->result, "Get requires an open io channel");
+ gtk_cups_result_set_error (request->result,
+ "Get requires an open io channel");
request->state = GTK_CUPS_GET_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
return;
}
- httpClearFields(request->http);
+ httpClearFields (request->http);
#ifdef HAVE_HTTP_AUTHSTRING
- httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
+ httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
#endif
- if (httpGet(request->http, request->resource))
+ if (httpGet (request->http, request->resource))
{
- if (httpReconnect(request->http))
+ if (httpReconnect (request->http))
{
request->state = GTK_CUPS_GET_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE;
httpReconnect (request->http);
/* Upgrade with encryption... */
- httpEncryption(request->http, HTTP_ENCRYPT_REQUIRED);
+ httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
request->attempts++;
goto again;
else
{
request->state = GTK_CUPS_GET_DONE;
- gtk_cups_result_set_error (request->result, "HTTP Error in GET %s", strerror (http_errno));
+ gtk_cups_result_set_error (request->result,
+ "HTTP Error in GET %s",
+ g_strerror (http_errno));
request->poll_state = GTK_CUPS_HTTP_IDLE;
- httpFlush(request->http);
+ httpFlush (request->http);
return;
}
request->poll_state = GTK_CUPS_HTTP_READ;
#if HAVE_CUPS_API_1_2
- bytes = httpRead2(request->http, buffer, sizeof(buffer));
+ bytes = httpRead2 (request->http, buffer, sizeof (buffer));
#else
- bytes = httpRead(request->http, buffer, sizeof(buffer));
+ bytes = httpRead (request->http, buffer, sizeof (buffer));
#endif /* HAVE_CUPS_API_1_2 */
GTK_NOTE (PRINTING,
/* GTK - The GIMP Toolkit
* gtkprintbackendcups.h: Default implementation of GtkPrintBackend
* for the Common Unix Print System (CUPS)
- * Copyright (C) 2003, Red Hat, Inc.
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
NULL,
cups_printer->device_uri);
- gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
+ IPP_TAG_URI, "printer-uri",
NULL, cups_printer->printer_uri);
title = gtk_print_job_get_title (job);
if (title)
- gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
- title);
+ gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION,
+ IPP_TAG_NAME, "job-name",
+ NULL, title);
gtk_print_settings_foreach (settings, add_cups_options, request);
cups_request_job_info (CupsJobPollData *data)
{
GtkCupsRequest *request;
- gchar *printer_uri;
+ gchar *job_uri;
request = gtk_cups_request_new (NULL,
GTK_CUPS_POST,
NULL,
NULL);
- printer_uri = g_strdup_printf ("ipp://localhost/jobs/%d", data->job_id);
+ job_uri = g_strdup_printf ("ipp://localhost/jobs/%d", data->job_id);
gtk_cups_request_ipp_add_string (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "job-uri", NULL, printer_uri);
- g_free (printer_uri);
+ "job-uri", NULL, job_uri);
+ g_free (job_uri);
cups_request_execute (data->print_backend,
request,
if (gtk_cups_result_is_error (result))
{
- g_warning ("Error getting printer list: %s", gtk_cups_result_get_error_string (result));
+ g_warning ("Error getting printer list: %s",
+ gtk_cups_result_get_error_string (result));
goto done;
}
member_uris = NULL;
while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
{
- if (!strcmp (attr->name, "printer-name") &&
+ if (strcmp (attr->name, "printer-name") == 0 &&
attr->value_tag == IPP_TAG_NAME)
printer_name = attr->values[0].string.text;
- else if (!strcmp (attr->name, "printer-uri-supported") &&
+ else if (strcmp (attr->name, "printer-uri-supported") == 0 &&
attr->value_tag == IPP_TAG_URI)
printer_uri = attr->values[0].string.text;
- else if (!strcmp (attr->name, "member-uris") &&
+ else if (strcmp (attr->name, "member-uris") == 0 &&
attr->value_tag == IPP_TAG_URI)
member_uris = attr->values[0].string.text;
else
resource);
#endif
- if (!strncmp (resource, "/printers/", 10))
+ if (strncmp (resource, "/printers/", 10) == 0)
{
cups_printer->ppd_name = g_strdup (resource + 10);
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: Setting ppd name '%s' for printer/class '%s'\n", cups_printer->ppd_name, printer_name));
}
- gethostname (uri, sizeof(uri));
+ gethostname (uri, sizeof (uri));
if (strcasecmp (uri, hostname) == 0)
strcpy (hostname, "localhost");
/* The ref is held by GtkPrintBackend, in add_printer() */
g_object_unref (printer);
-
if (attr == NULL)
break;
return TRUE;
g_object_ref (cups_backend);
+
GDK_THREADS_LEAVE ();
cups_backend->list_printers_pending = TRUE;
(GtkPrintCupsResponseCallbackFunc) cups_request_printer_list_cb,
request,
NULL);
+
GDK_THREADS_ENTER ();
+
g_object_unref (cups_backend);
return TRUE;